package com.cyzy;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class RTMPHandler extends SimpleChannelInboundHandler<ByteBuf> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        // 处理RTMP请求
        System.out.println("Received message: " + msg.toString());
        // 发送响应
        ctx.writeAndFlush(msg.copy()); // 使用copy()避免直接操作原始ByteBuf
        // 不需要手动释放msg
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}